import OceanComponent from './OceanComponent';
import OFormItems from '../../components/FormItems.vue';
import FormItem from './FormItem';
import { FormItemProps } from '../common/props';

class FormItems<T = any> extends OceanComponent<TFormItemsProps> {
  items: FormItem<T>[] = [];
  model: any;
  path: string;
  constructor(attrs: TFormItemsProps) {
    super(OFormItems, attrs, {
      model: {},
      cols: '1',
      collapsed: false,
      collapsedRows: 1
    });
    this.model = this.attrs.model;
    this.path = this.attrs.path;
  }
  item(label: string, key: keyof T, props?: FormItemProps): FormItem<T> {
    let item: FormItem<T> = new FormItem<T>(label, key, props);
    this.items.push(item);
    return item;
  }
}

export default FormItems;
